package ch.abcm.remsmobile.REMSMobile.externNotifier;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class ExternNotifierController extends BroadcastReceiver {

    private static final String TAG = "ExternNotifierController";
    private static final String EXTERN_NOTIFIER_ACTION = "ch.bfh.abcm.rems.EXTERN_NOTIFIER_ACTION";
    private static final String MESSAGE_EXTRA_TYPE = "MessageType";
    private static final String MESSAGE_EXTRA_TEXT = "MessageText";

    private enum MessageType {
        SIMPLE, PERIODICUPDATE, SYSTEAM_ERROR, MEASUREMNETDIVERGENCE;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "Received EXTERN_NOTIFIER_ACTION");
        Log.e(TAG, "NOT IMPLEMENTED");

        String msg = "Type: " + intent.getExtras().get(MESSAGE_EXTRA_TYPE) + " Text: "
                + intent.getStringExtra(MESSAGE_EXTRA_TEXT);
        Log.e(TAG, msg);
        Toast.makeText(context, intent.getStringExtra(MESSAGE_EXTRA_TEXT), Toast.LENGTH_LONG).show();
    }

    public static Intent getSimpleMessageIntent(String message) {
        Intent simpleMessageIntent = new Intent(EXTERN_NOTIFIER_ACTION);
        simpleMessageIntent.putExtra(MESSAGE_EXTRA_TYPE, MessageType.SIMPLE);
        simpleMessageIntent.putExtra(MESSAGE_EXTRA_TEXT, message);
        return simpleMessageIntent;
    }
}
